package com.ruoyi.crm.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.crm.domain.CrmBank;
import com.ruoyi.crm.service.ICrmBankService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 银行参数Controller
 * 
 * @author ruoyi
 * @date 2024-03-04
 */
@RestController
@RequestMapping("/crm/bank")
public class CrmBankController extends BaseController
{
    @Autowired
    private ICrmBankService crmBankService;

    /**
     * 查询银行参数列表
     */
    @PreAuthorize("@ss.hasPermi('crm:bank:list')")
    @GetMapping("/list")
    public TableDataInfo list(CrmBank crmBank)
    {
        startPage();
        List<CrmBank> list = crmBankService.selectCrmBankList(crmBank);
        return getDataTable(list);
    }

    /**
     * 导出银行参数列表
     */
    @PreAuthorize("@ss.hasPermi('crm:bank:export')")
    @Log(title = "银行参数", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CrmBank crmBank)
    {
        List<CrmBank> list = crmBankService.selectCrmBankList(crmBank);
        ExcelUtil<CrmBank> util = new ExcelUtil<CrmBank>(CrmBank.class);
        util.exportExcel(response, list, "银行参数数据");
    }

    /**
     * 获取银行参数详细信息
     */
    @PreAuthorize("@ss.hasPermi('crm:bank:query')")
    @GetMapping(value = "/{bankId}")
    public AjaxResult getInfo(@PathVariable("bankId") Long bankId)
    {
        return success(crmBankService.selectCrmBankByBankId(bankId));
    }

    /**
     * 新增银行参数
     */
    @PreAuthorize("@ss.hasPermi('crm:bank:add')")
    @Log(title = "银行参数", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrmBank crmBank)
    {
        return toAjax(crmBankService.insertCrmBank(crmBank));
    }

    /**
     * 修改银行参数
     */
    @PreAuthorize("@ss.hasPermi('crm:bank:edit')")
    @Log(title = "银行参数", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrmBank crmBank)
    {
        return toAjax(crmBankService.updateCrmBank(crmBank));
    }

    /**
     * 删除银行参数
     */
    @PreAuthorize("@ss.hasPermi('crm:bank:remove')")
    @Log(title = "银行参数", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bankIds}")
    public AjaxResult remove(@PathVariable Long[] bankIds)
    {
        return toAjax(crmBankService.deleteCrmBankByBankIds(bankIds));
    }
}
